
package uk.ac.cam.cl.oscar.edgefinder;

import java.lang.Math;

/** A line described by its angle to the horizontal, and distance from the origin. */
public class RhoLine {

	/** The distance from the origin, in normalised coordinates (@see NormalisedPoint) */
	public double rho;
	
	/** Angle from the horizontal, in normal trig layout (i.e. first quadrant) */
	public double theta;
	
	public RhoLine (double r, double t) {
		rho = r;
		theta = t;
	}
	
	public NormalisedPoint intersect (RhoLine b) 
	{
		NormalisedPoint p = new NormalisedPoint();
		p.setNormalX ( 
			( b.rho*Math.sin(this.theta) - this.rho*Math.sin(b.theta) ) 
			/ 
			( Math.cos(b.theta)*Math.sin(this.theta) - Math.cos(this.theta)*Math.sin(b.theta) ) 
		);
		
		p.setNormalY ( -Math.cos(this.theta) / Math.sin(this.theta) * p.normalX() + this.rho / Math.sin(this.theta) );
		
		return p;
	}

	public NormalisedPoint getPointAtX (double x)
	{
		NormalisedPoint p = new NormalisedPoint();
		p.setNormalX ( x );
		p.setNormalY ( -Math.cos(this.theta) / Math.sin(this.theta) * p.normalX() + this.rho / Math.sin(this.theta) );
		
		return p;
	}
}